package com.hxx.day4.service.impl;

import com.hxx.day4.domain.Person;
import com.hxx.day4.service.HxxService;

import java.util.ArrayList;
import java.util.List;

public class HxxServiceImpl implements HxxService {

    //模拟数据库
    private List db = new ArrayList();
    @Override
    public void save(Person person) {
        db.add(person);
    }

    @Override
    public void update(Person person) {
        db.set(db.indexOf(person),person);
    }

    @Override
    public void delete(Person person) {
        db.remove(person);
    }

    @Override
    public Person findById(Person person) {
        for (Object o : db) {
            if (((Person)o).getId().equals(person.getId())) {
                return (Person)o;
            }
        }
        return null;
    }

    @Override
    public List findAll() {
        if (db.size()>0)
            return db;
        return null;
    }
}
